package com.moxi.service;

import com.moxi.model.News;
import com.moxi.model.User;
import com.moxi.util.Constant;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserService {

    /**
     * 查询用户信息
     * @param user
     * @return
     */
    @Select({
            "<script>",
            "SELECT * FROM MOXI.ADMIN",
            "WHERE state = 0",
            "<when test='userName!=null'>",
            "AND userName LIKE '%' #{userName} '%'",
            "</when>",
            "</script>"
    })
    List<User> list(User user);

    /**
     * 查询总用户数
     * @param user
     * @return
     */
    @Select({"select count(*) from admin where state=0"})
    int count(User user);

    /**
     * 根据id查询用户信息
     * @param user
     * @return
     */
    @Select("SELECT * FROM MOXI.ADMIN WHERE ID = #{id};")
    User findById(User user);

    /**
     * 根据id删除用户信息
     * @param user
     * @return
     */
    @Delete("DELETE FROM ADMIN WHERE ID=#{id}")
    boolean delete(User user);

    /**
     * 添加用户信息
     * @param user
     * @return
     */
    @Insert("insert into admin (userName,password,realName,age,phoneNumber,addDate) values(#{userName},#{password},#{realName},#{age},#{phoneNumber},#{addDate})")
    boolean insert(User user);

    /**
     * 修改用户信息
     * @param user
     * @return
     */
    @Update("update admin set userName=#{userName},password=#{password},realName=#{realName},age=#{age},phoneNumber=#{phoneNumber},updateDate=#{updateDate} where id=#{id}")
    boolean update(User user);
}
